/**
 * Initalisiert die Datentabellen
 */

$(document).ready(function() {

	$('#lectures').dataTable({
		"aaSorting" : [ [ 0, "asc" ] ],
		"aoColumnDefs" : [ {
			"bSortable" : false,
			"aTargets" : [ 2 ]
		} ],
		"aoColumns": [null, null, {"sWidth": "60px"}],
		"aLengthMenu" : [ [ 10, 25, 50, -1 ], [ 10, 25, 50, "Alle" ] ]
	});
	
		
});

/**
 *  Verschieben von Vorlesungen zwischen den Boxen
 */

function moveSelectedItems(source, destination){
    var selected = $(source+' option:selected').remove();
    var sorted = $.makeArray($(destination+' option').add(selected)).sort(function(a,b){
        return $(a).text() > $(b).text() ? 1:-1;
    });
    $(destination).empty().append(sorted);
}

$(document).ready(function(){
    $('#lectures-add').click(function(){
        moveSelectedItems('#lectures-available', '#lectures-selected');
    });

    $('#lectures-remove').click(function(){
        moveSelectedItems('#lectures-selected', '#lectures-available');
    });
    $('#createform').submit(function(){
        $('#lectures-selected option').attr('selected', 'true');
    });
});

